package ModelLayer;
import java.util.ArrayList;
import java.util.Date;

public class Product
{
    private int id,stock;
    private String name,description;
    private double price,finalPrice;
    private DiscountProduct discount;
    private ArrayList<Product> products;
    private String location;
    
    public Product(int id, String name, String description, double price, String location)
    {
        this.id = id;
        this.name = name;
        this.description = description;
        this.price = price;
        this.finalPrice = price;
        this.discount = new DiscountProduct();
        this.location = location;
        products = new ArrayList<>();
    }
    
    public void addPiece(Product prod)
    {
        products.add(prod);
        price += prod.getPrice();
        finalPrice=price;
    }
    
    public boolean removePiece(int idP)
    {
        int j = products.size();
        for(int i=0;i<j;i++)
            if(products.get(i).getId() == idP) {price -= products.get(i).getPrice(); products.remove(i);return true;}
        
        return false;
    }
    
    public void updateStock() { this.stock--; }

    public void addStock(int add) { this.stock += add; }

    public void setStock(int stock) { this.stock = stock;  }

    public void setPrice(double newPrice) {  this.price = newPrice; }

    public void setDescription(String param) { this.description = param;  }

    public void setName(String param) { this.name = param; }
    
    public void setLocation(String param) { this.location = param; }
    

    public String getName() { return this.name; }

    public String getDescription() { return this.description; }

    public double getPrice() { return this.price; }
    public double getFinalPrice() { return this.finalPrice; }

    public int getStock() { return this.stock; }
    
    public int getId() { return id; }
    
    public String getLocation() { return this.location; }
    
    
    public void setDiscount(double disc, Date endDate) 
    { 
        discount.setDiscount(disc);
        discount.setEndDate(endDate);
        
        finalPrice = price - price*disc/100;
    }
    
    public double getDiscount()  { return discount.getDiscount(); }
    public Date getEndDateDiscount() { return discount.getEndDate(); }
    public int getSizeParts() { return products.size(); }
    public Product getPartFromId(int id) { return products.get(id); }
}
